<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<script src="../../resources/js-test.js"></script>
<script src="resources/input-modifiers.js"></script>
<script>
description("Tests MouseEvent.getModifierState()");

var lastMouseEvent;

function recordMouseEvent(ev) {
    lastMouseEvent = ev;
    ev.preventDefault();
}

function testMouseEventWithModifiers(button, eventModifiers) {
    eventSender.mouseDown(button, eventModifiers);
    shouldBe("lastMouseEvent.type", '"mousedown"');
    shouldEvaluateTo("lastMouseEvent.button", button);
    forEachModifier(function(modifierInitName, modifierName, eventSenderName) {
        var expectedModifierState = eventModifiers.indexOf(eventSenderName) >= 0;
        shouldEvaluateTo("lastMouseEvent.getModifierState('" + modifierName + "')", expectedModifierState);
    });

    forEachLegacyModifier(function(attr) {
        var expectedModifierState = eventModifiers.indexOf(attr) >= 0;
        shouldEvaluateTo("lastMouseEvent." + attr, expectedModifierState);
    });
}

if (window.eventSender) {
    document.addEventListener("mousedown", recordMouseEvent, false);
    testMouseEventWithModifiers(0, ["ctrlKey"]);
    testMouseEventWithModifiers(1, ["shiftKey"]);
    testMouseEventWithModifiers(2, ["altKey"]);
    testMouseEventWithModifiers(0, ["metaKey"]);
    testMouseEventWithModifiers(1, ["ctrlKey", "shiftKey"]);
    testMouseEventWithModifiers(2, ["ctrlKey", "shiftKey", "altKey"]);
    testMouseEventWithModifiers(1, ["ctrlKey", "shiftKey", "altKey", "metaKey"]);

    forEachModifier( function(eventInitName, eventModifierName, eventSenderName) {
      testMouseEventWithModifiers(1, [eventSenderName]);
    });
    var isMacOSX = navigator.userAgent.indexOf("Mac OS X") != -1;
    eventSender.mouseDown(2, [isMacOSX ? "metaKey" : "ctrlKey"]);
    shouldBe("lastMouseEvent.type", '"mousedown"');
    shouldEvaluateTo("lastMouseEvent.button", 2);
    shouldEvaluateTo("lastMouseEvent.getModifierState('Accel')", "true");
} else {
    debug("This test requires DumpRenderTree.");
}
</script>
